<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>坐标</title>
<script type="text/javascript">
  var a, b;
  function coordinate(event) {
    a = event.clientX;
    b = event.clientY;
    document.getElementById("span1").innerText = "x坐标为" + a + "，y坐标为" + b;
  }
  function message(event) {
    a = event.clientX;
    b = event.clientY;
    alert("x坐标为" + a + "，y坐标为" + b);
  }
</script>
</head>
<body onmousemove="coordinate(event)" onclick="message(event)">
  <p>移动鼠标，屏幕将显示鼠标停留位置的坐标</p>
  <p>点击后，将弹窗显示当前位置的坐标</p>
  <span id="span1"></span>
</body>
</html>